/**
 * 泛型
 */

function getData<T>(str: T): T {
	return str;
}
getData<string>("字符串类型");

interface A<T> {
	(str: T): T;
}
const fun1: A<number> = (num) => {
	return num;
};
fun1(1);
const a = 111;
class minClas<T> {
	list: T[] = [];
	add(num: T): void {
		this.list.push(num);
	}
	min(): void {
		let result: T = this.list[0];
		for (let i = 0; i < this.list.length; i++) {
			if (this.list[i] < result) {
				result = this.list[i];
			}
		}
		console.log(result);
	}
}

let aa = new minClas<number>();
aa.add(1);
aa.add(2);
aa.add(3);
aa.min();

//类作为参数的泛型

class User {
	username: string | undefined;
	password: string | undefined;
}

class Mysql<T> {
	add(params: T): boolean {
		console.log(params);
		return true;
	}
	update(params: T): boolean {
		console.log(params);
		return true;
	}
}

let user = new User();
user.username = "Ren";
user.password = "123456";

let mysql = new Mysql<User>();
mysql.add(user);
